2015-08-21.sql 2.4 KB

1234567891011121314151617181920212223242526272829303132
  1. 
  2. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_TwoSalesOrder')
  3. BEGIN
  4. DROP VIEW [dbo].Vw_TwoSalesOrder
  5. END
  6. GO
  7. create View Vw_TwoSalesOrder
  8. as
  9. SELECT
  10. dbo.tb_ErpTwoSalesOrder.ID,
  11. Tsorder_Number,
  12. Tsorder_Name,
  13. (case Tsorder_CustomerName
  14. when '' then (select Cus_Name from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber)
  15. else Tsorder_CustomerName end) as Tsorder_CustomerName,
  16. (case Tsorder_CustomerName
  17. when '' then (select Cus_Telephone from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber)
  18. else Tsorder_Telephone end) as Tsorder_Telephone,
  19. (select Cus_NamePinyin from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Cus_NamePinyin,
  20. Tsorder_Money,
  21. Tsorder_Quantity,
  22. Tsorder_Category,
  23. Tsorder_OpenSingle,
  24. Tsorder_PersonHandling,
  25. Tsorder_Remark,
  26. Tsorder_CreateDatetime,
  27. Tsorder_UpdateDatetime,
  28. dbo.fn_CheckUserIDGetUserName(Tsorder_OpenSingle) AS [User_Name],
  29. dbo.fn_CheckUserIDGetUserName(Tsorder_PersonHandling) AS Tsorder_PersonHandlingName,
  30. dbo.fn_GetClassCodeToName(Tsorder_Category,Tsorder_Category) AS Tsorder_CategoryName,
  31. Tsorder_CustomerNumber
  32. FROM dbo.tb_ErpTwoSalesOrder